<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'
import {optionsAction} from '@/api/statistics'
export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '350px'
    },
    autoResize: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      chart: null,

      datas:{}
    }
  },
  watch: {
  },
  mounted() {
    this.$nextTick(() => {
      this.initData()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initData(){
      optionsAction("waybill").then(response=>{
        this.datas =  response.data;
      }).finally(()=>{
         this.initChart()
      })
    },
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')
      this.setOptions()
    },
    setOptions({ expectedData, actualData } = {}) {
      this.chart.setOption({
        color:['#5470c6','#9a60b4','#ee6666','#3ba272','#73c0de','#91cc75', '#fac858', '#fc8452', '#ea7ccc'],
        tooltip: {
            trigger: 'axis'
          },
          legend: {
            data: ['公安', '检察院', '法院', '中心库']
          },
          grid: {
            left: '1%',
            right: '1%',
            bottom: '1%',
            containLabel: true
          },
          xAxis: {
            type: 'category',
            boundaryGap: false,
            // data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
            data:this.datas.xData
          },
          yAxis: {
            type: 'value'
          },
          series:this.datas.yData
          // series: [
          //   {
          //     name: '沙县区',
          //     type: 'line',
          //     // stack: 'Total',
          //     data: [120, 132, 101, 134, 90, 230, 210, 132, 101, 134, 90, 230]
          //   },
          //   {
          //     name: '永安市',
          //     type: 'line',
          //     // stack: 'Total',
          //     data: [220, 182, 191, 234, 290, 330, 310, 182, 191, 234, 290, 330]
          //   },
          //   {
          //     name: '宁化县',
          //     type: 'line',
          //     // stack: 'Total',
          //     data: [150, 232, 201, 154, 190, 330, 410, 232, 201, 154, 190, 330]
          //   },
          //   {
          //     name: '中心库',
          //     type: 'line',
          //     // stack: 'Total',
          //     data: [320, 332, 301, 334, 390, 330, 320, 332, 301, 334, 390, 330]
          //   }
          // ]
      })
    }
  }
}
</script>
